#include"head.h"
#include"funcs.h"

using namespace std;

map<char, string> First;
map<char, string> Last;

char Vt[] = "some stoping words";
char Vn[] = "some not stoping words";

void creat_first(queue<string> ruls) {

	initMap(Vn, First);

	while (!ruls.empty()) {
		
		string& con = ruls.front();
		
		for (size_t i = 1; i < con.size(); i++) {
			if (inString(Vt, con[i])) {
				First[con[0]].push_back(con[i]);
				for (size_t s = i - 1; s >= 1; s--) {
					strUnion(First[con[0]], First[con[s]]);
				}
				break;
			}
			if (!inString(Vt, con[i]) && First[con[i]].empty()) {
				ruls.push(con);
				break;
			}
		}

		ruls.pop();
	}
}

void creat_last(queue<string>& ruls) {

	initMap(Vn, Last);

	while (!ruls.empty()) {

		string& con = ruls.front();

		for (size_t i = con.size(); i >=1 ; i--) {
			if (inString(Vt, con[i])) {
				Last[con[0]].push_back(con[i]);
				for (size_t s = i +1; s <con.size(); s++) {
					strUnion(Last[con[0]], Last[con[s]]);
				}
				break;
			}
			if (!inString(Vt, con[i]) && Last[con[i]].empty()) {
				ruls.push(con);
				break;
			}
		}

		ruls.pop();
	}
}